package com.liuyu.mall2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuyu.mall2.entity.Manager;
import com.liuyu.mall2.exception.AccountExistException;
import com.liuyu.mall2.mapper.ManagerMapper;
import com.liuyu.mall2.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 刘宇
 * @classname ManagerServiceImpl
 * @time 2025/4/8
 * @project mall2
 */
@Service
public class ManagerServiceImpl extends ServiceImpl<ManagerMapper, Manager> implements ManagerService {

@Autowired
private ManagerMapper managerMapper;
    @Override
    public void add(Manager manager) {
        
        QueryWrapper<Manager> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account",manager.getAccount());
        Long count = managerMapper.selectCount(queryWrapper);
        if(count>0){
            throw new AccountExistException("账号"+manager.getAccount()+"已存在");
        }
        managerMapper.insert(manager);
    }

    @Override
    public Manager login(String account, String password) {
//        QueryWrapper<Manager> queryWrapper = new QueryWrapper<>();
        LambdaQueryWrapper<Manager> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Manager::getAccount,account);
        queryWrapper.eq(Manager::getPassword,password);
        Manager manager=managerMapper.selectOne(queryWrapper);
        return manager;
    }
}


